(SST) ShlWAPI.pas Version 1.08

Developer Reference
(SST)ShlWAPI PathRemoveArgs Function
Strips the command line parameters/arguments (if present) from the specified string.
Scope
Global (i.e. this function can be called/accessed from code in any unit that includes/uses (SST)ShlWAPI.pas).
Syntax
procedure PathRemoveArgs(pszPath : LPSTR);
Parameters
pszPath [in/out] Depending on which version of the function is called, a pointer to either a null-terminated ANSI or Unicode character buffer, that, prior to the call, contains the entire command line string. When the function returns the buffer contains the modified string.
Return Values
None (i.e. this function does not return a value).
Remarks
The entire command line (or other) string, passed to the function, should not exceed MAX_PATH (= 260) ANSI or Unicode characters in length. This includes the terminating null character.
If the first path contains blanks/spaces, it must be enclosed in quotation marks (i.e. "), otherwise the function will return only that part of the first path, up to the first encountered space/blank.
Other than comparing the lengths of the string in the (input/output) buffer, prior to, and after the function call, there is no easy way to determine if the function made any modifications to the original string.
The function supports both the use of short, DOS, 8.3 and long file names.
Paths may be specified using either Windows or Unix path separators (i.e. "\" or "/", respectively).
Altlhough the function is typically used to determine the location and file name of the executable from which it is called, it can also be used to separate an arbitrary path from supplementary/trailing information, including further paths.
The function does not verify the existence of the specified path or paths.
If the function is called with a null-pointer as the parameter, it does not raise an exception, nor is the thread specific error code, returned by the Windows API function GetLastError, modified.
Example
PROCEDURE TForm4.TestShlWAPIPathRemoveArgs(Sender : TObject); VAR pathtotestbuf : ARRAY[0 .. 512] OF CHAR; VAR newinfoline : STRING; BEGIN FillChar(pathtotestbuf, SizeOf(pathtotestbuf), #0); newinfoline := ''; pathtotestbuf := 'C:\Windows\system32\notepad.exe'; newinfoline := 'PathRemoveArgs called with ' + pathtotestbuf; Memo1.Lines.Add(newinfoline); PathRemoveArgs(pathtotestbuf); newinfoline := 'after the call : ' + pathtotestbuf; Memo1.Lines.Add(newinfoline); pathtotestbuf := 'C:\Windows\system32\mspaint.exe C:\Windows\Web\Wallpaper\img16.jpg'; newinfoline := 'PathRemoveArgs called with ' + pathtotestbuf; Memo1.Lines.Add(newinfoline); PathRemoveArgs(pathtotestbuf); newinfoline := 'after the call : ' + pathtotestbuf; Memo1.Lines.Add(newinfoline); pathtotestbuf := 'C:\Windows\system32\calc.exe /open /SomeFile.clc'; newinfoline := 'PathRemoveArgs called with ' + pathtotestbuf; Memo1.Lines.Add(newinfoline); PathRemoveArgs(pathtotestbuf); newinfoline := 'after the call : ' + pathtotestbuf; Memo1.Lines.Add(newinfoline); pathtotestbuf := 'C:\Windows\system32\cmd.exe -D /DummyParam -S "DummyParam2"'; newinfoline := 'PathRemoveArgs called with ' + pathtotestbuf; Memo1.Lines.Add(newinfoline); PathRemoveArgs(pathtotestbuf); newinfoline := 'after the call : ' + pathtotestbuf; Memo1.Lines.Add(newinfoline); pathtotestbuf := 'C:\Program Files\Windows Mail\wab.exe -DummyParam /a "DummyParam2"'; newinfoline := 'PathRemoveArgs called with ' + pathtotestbuf; Memo1.Lines.Add(newinfoline); PathRemoveArgs(pathtotestbuf); newinfoline := 'after the call : ' + pathtotestbuf; Memo1.Lines.Add(newinfoline); pathtotestbuf := '"C:\Program Files\Windows Mail\WinMail.exe" -Dummy Param /a "DummyParam 2"'; newinfoline := 'PathRemoveArgs called with ' + pathtotestbuf; Memo1.Lines.Add(newinfoline); PathRemoveArgs(pathtotestbuf); newinfoline := 'after the call : ' + pathtotestbuf; Memo1.Lines.Add(newinfoline); pathtotestbuf := 'D:\PROGRA~1\MI6841~1\90\Tools\binn\NonExist.exe -A /S -pP -E'; newinfoline := 'PathRemoveArgs called with ' + pathtotestbuf; Memo1.Lines.Add(newinfoline); PathRemoveArgs(pathtotestbuf); newinfoline := 'after the call : ' + pathtotestbuf; Memo1.Lines.Add(newinfoline); pathtotestbuf := 'F:\PROGRA~1\Tools\Win-NT\No-Exist.exe -Z /T -rL -X'; newinfoline := 'PathRemoveArgs called with ' + pathtotestbuf; Memo1.Lines.Add(newinfoline); PathRemoveArgs(pathtotestbuf); newinfoline := 'after the call : ' + pathtotestbuf; Memo1.Lines.Add(newinfoline); pathtotestbuf := '%ProgramFiles%\Windows NT\Accessories\wordpad.exe C:\Documents\TestFile.rtf'; newinfoline := 'PathRemoveArgs called with ' + pathtotestbuf; Memo1.Lines.Add(newinfoline); PathRemoveArgs(pathtotestbuf); newinfoline := 'after the call : ' + pathtotestbuf; Memo1.Lines.Add(newinfoline); pathtotestbuf := '"%ProgramFiles%\Windows NT\Accessories\wordpad.exe" C:\Documents\Wordpad\TestFile.rtf'; newinfoline := 'PathRemoveArgs called with ' + pathtotestbuf; Memo1.Lines.Add(newinfoline); PathRemoveArgs(pathtotestbuf); newinfoline := 'after the call : ' + pathtotestbuf; Memo1.Lines.Add(newinfoline); pathtotestbuf := '..\Windows Journal\wordpad.exe C:\Documents\Journals\Shorthand.jtp'; newinfoline := 'PathRemoveArgs called with ' + pathtotestbuf; Memo1.Lines.Add(newinfoline); PathRemoveArgs(pathtotestbuf); newinfoline := 'after the call : ' + pathtotestbuf; Memo1.Lines.Add(newinfoline); pathtotestbuf := '"..\Windows Journal\wordpad.exe" D:\Scrap\Music.jtp'; newinfoline := 'PathRemoveArgs called with ' + pathtotestbuf; Memo1.Lines.Add(newinfoline); PathRemoveArgs(pathtotestbuf); newinfoline := 'after the call : ' + pathtotestbuf; Memo1.Lines.Add(newinfoline); pathtotestbuf := 'X:\DummyDir\DummyDir2\Noexist.doc -T /W /V -h'; newinfoline := 'PathRemoveArgs called with ' + pathtotestbuf; Memo1.Lines.Add(newinfoline); PathRemoveArgs(pathtotestbuf); newinfoline := 'after the call : ' + pathtotestbuf; Memo1.Lines.Add(newinfoline); pathtotestbuf := 'Y:/UnixDir/UnixDir2/Noexist -R /P /F -? C:\Root\SubDir'; newinfoline := 'PathRemoveArgs called with ' + pathtotestbuf; Memo1.Lines.Add(newinfoline); PathRemoveArgs(pathtotestbuf); newinfoline := 'after the call : ' + pathtotestbuf; Memo1.Lines.Add(newinfoline); Memo1.Lines.Add(''); END;
Under Windwos Vista the above example produced the following output:
PathRemoveArgs called with C:\Windows\system32\notepad.exe after the call : C:\Windows\system32\notepad.exe PathRemoveArgs called with C:\Windows\system32\mspaint.exe C:\Windows\Web\Wallpaper\img16.jpg after the call : C:\Windows\system32\mspaint.exe PathRemoveArgs called with C:\Windows\system32\calc.exe /open /SomeFile.clc after the call : C:\Windows\system32\calc.exe PathRemoveArgs called with C:\Windows\system32\cmd.exe -D /DummyParam -S "DummyParam2" after the call : C:\Windows\system32\cmd.exe PathRemoveArgs called with C:\Program Files\Windows Mail\wab.exe -DummyParam /a "DummyParam2" after the call : C:\Program PathRemoveArgs called with "C:\Program Files\Windows Mail\WinMail.exe" -Dummy Param /a "DummyParam 2" after the call : "C:\Program Files\Windows Mail\WinMail.exe" PathRemoveArgs called with D:\PROGRA~1\MI6841~1\90\Tools\binn\NonExist.exe -A /S -pP -E after the call : D:\PROGRA~1\MI6841~1\90\Tools\binn\NonExist.exe PathRemoveArgs called with F:\PROGRA~1\Tools\Win-NT\No-Exist.exe -Z /T -rL -X after the call : F:\PROGRA~1\Tools\Win-NT\No-Exist.exe PathRemoveArgs called with %ProgramFiles%\Windows NT\Accessories\wordpad.exe C:\Documents\TestFile.rtf after the call : %ProgramFiles%\Windows PathRemoveArgs called with "%ProgramFiles%\Windows NT\Accessories\wordpad.exe" C:\Documents\Wordpad\TestFile.rtf after the call : "%ProgramFiles%\Windows NT\Accessories\wordpad.exe" PathRemoveArgs called with ..\Windows Journal\wordpad.exe C:\Documents\Journals\Shorthand.jtp after the call : ..\Windows PathRemoveArgs called with "..\Windows Journal\wordpad.exe" D:\Scrap\Music.jtp after the call : "..\Windows Journal\wordpad.exe" PathRemoveArgs called with X:\DummyDir\DummyDir2\Noexist.doc -T /W /V -h after the call : X:\DummyDir\DummyDir2\Noexist.doc PathRemoveArgs called with Y:/UnixDir/UnixDir2/Noexist -R /P /F -? C:\Root\SubDir after the call : Y:/UnixDir/UnixDir2/Noexist
Requirements
Unit: Declared and imported in (SST)ShlWAPI.pas
Library: (SST)ShlWAPI.dcu/(SST)ShlWAPI.obj
Unicode: Implemented as ANSI (PathRemoveArgs and PathRemoveArgsA) and Unicode (PathRemoveArgsW) functions.
Min. ShlWAPI.dll version according to MS SDK doc.: 4.71
Min. ShlWAPI.dll version based on SST research: 4.71
Min. OS version(s) according to Microsoft SDK doc.: Windows 2000, Windows NT 4.0 with Internet Explorer 4.0, Windows 98, Windows 95 with Internet Explorer 4.0
Min. OS version(s) according to SST research.: Windows NT 4.0 with IE 4.0, Windows 95 with IE 4.0, Windows 98, Windows 2000 and later
See Also
PathGetArgs, PathFindNextComponent, PathFindSuffixArray.
 
Windows APIs: GetLastError, SetLastError, PathRemoveArgs, PathGetArgs, PathParseIconLocation


Document/Contents version 1.00
Page/URI last updated on 07.12.2023
 
Copyright © Stoelzel Software Technologie (SST) 2010 - 2015
Suggestions and comments mail to:
webmaster@stoelzelsoftwaretech.com